package com.example;

import org.beetl.sql.core.ClasspathLoader;
import org.beetl.sql.core.ConnectionSource;
import org.beetl.sql.core.ConnectionSourceHelper;
import org.beetl.sql.core.Interceptor;
import org.beetl.sql.core.SQLLoader;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.UnderlinedNameConversion;
import org.beetl.sql.core.db.DBStyle;
import org.beetl.sql.core.db.MySqlStyle;
import org.beetl.sql.ext.DebugInterceptor;
import org.beetl.sql.ext.gen.GenConfig;
import org.beetl.sql.ext.gen.MapperCodeGen;

public class GenerateCode {
	
	private final static String driver = "com.mysql.jdbc.Driver";
	private final static String url = "jdbc:mysql://127.0.0.1:3306/renren-security?characterEncoding=utf8";
	private final static String userName = "root";
	private final static String password = "root";

	public static void main(String[] args) throws Exception {
		ConnectionSource source = ConnectionSourceHelper.getSimple(driver, url, userName, password);
		DBStyle mysql = new MySqlStyle();
		// sql语句放在classpagth的/sql 目录下
		SQLLoader loader = new ClasspathLoader("/sql");
		// 数据库命名跟java命名一样，所以采用DefaultNameConversion，还有一个是UnderlinedNameConversion，下划线风格的
		//所以采用DefaultNameConversion nc = new 所以采用DefaultNameConversion();
		UnderlinedNameConversion nc = new UnderlinedNameConversion();
		// 最后，创建一个SQLManager,DebugInterceptor 不是必须的，但可以通过它查看sql执行情况
		SQLManager sqlManager = new SQLManager(mysql, loader, source, nc, new Interceptor[] { new DebugInterceptor() });
		GenConfig config = new GenConfig();
		config.preferBigDecimal(true);
		config.setBaseClass("com.example");
		MapperCodeGen mapper = new MapperCodeGen("com.example.dao");
		config.codeGens.add(mapper);
		//sqlManager.genPojoCodeToConsole("sys_user", config);
		sqlManager.genPojoCode("sys_menu","com.example.entity");
		sqlManager.genSQLFile("sys_menu");
	}

}
